<template>
  <div class="appidSelect">
    <a-select v-model="id" @change="selectChange" :placeholder="placeholder" style="width: 178px">
      <a-select-option v-for="item in optionList" :key="item.Id" :value="item.Id"> {{ item.AppName ||
        item.ConfigurationItemsContent || item.SourceChildName }} </a-select-option>
    </a-select>
  </div>
</template>

<script>
import {
  appIdList, appIdDetail, configurationItemsFind, chidataItemslist,
  childataItems,
  appidSelect
} from "@/api/ytdg"
export default {
  naem: 'AppidSelect',
  props: {
    selectType: {
      default: 'appId'
    },
    appId: {},
    index: {},
  },
  data() {
    return {
      optionList: [],
      id: undefined,
      placeholder: '请选择appID'
    }
  },
  // watch: {
  //   'appId': {
  //     handler(newVal, oldVal) {
  //       this.getList()
  //     }
  //   }
  // },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      switch (this.selectType) {
        case 'ontroller':  // 数据掌控者
          this.placeholder = '请选择数据掌控者'
          configurationItemsFind({ state: 11, content: 'NSC' }).then((res) => {
            this.optionList = res.data
          })
          break;
        case 'dataItem':  // 数据掌控者
          this.placeholder = '请选择数据项'
          chidataItemslist().then((res) => {
            this.optionList = res.data
          })
          break;
        case 'dataCity':  // 城市
          this.placeholder = '请选择城市'
          configurationItemsFind({ state: 3 }).then((res) => {
            this.optionList = res.data
          })
          break;

          case 'dataStorage':  // 数据存放地点
          this.placeholder = '请选择数据存放地点'
          configurationItemsFind({ state: 4 }).then((res) => {
            this.optionList = res.data
          })
          break;

          case 'dataSource':  // 数据来源
          this.placeholder = '请选择数据来源'
          appidSelect().then((res) => {
            this.optionList = res.data
            console.log(res)
          })
          break;
          
        default:
          this.placeholder = '请选择appID'
          appIdList().then((res) => {
            this.optionList = res.data.Lists
          })
      }
    },
    selectChange() {
      let idAndIndex = {
        id: this.id,
        index: this.index
      }
      switch (this.selectType) {
        case 'ontroller':         // 数据掌控者
          this.$emit('getSelectId', this.id)
          break;

        case 'dataItem':          // 数据项
          childataItems({ data: 4 }).then((res) => {
            idAndIndex.SourceSensitivityLevel = res.data.SourceSensitivityLevel
            idAndIndex.SourceDataLevel = res.data.SourceDataLevel
          })
          this.$emit('getSelectId', idAndIndex)
          break;

        case 'dataCity':         // 城市
          this.$emit('getSelectId', idAndIndex)
          break;

        case 'dataCity':         // 数据存放地点
          this.$emit('getSelectId', idAndIndex)
          break;


        default:                  // appid
          appIdDetail({ id: this.id }).then((res) => {
            this.$emit('getSelectInfo', res.data)
          })
          this.$emit('getSelectId', this.id)
      }
    },
  },
}
</script>
